package vn.pdg.zoombie.ui;

import vn.pdg.zoombie.bean.DataApplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;

public class BaseActivity extends Activity implements OnClickListener {
	private Button homeMenu, profileMenu, matchmakerMenu, galleryMenu,
			createMenu;
	protected LinearLayout layoutMenu;
	protected LinearLayout titleLayout;
	public DataApplication dataApplication;

	@Override
	protected void onCreate(Bundle aSavedInstanceStatea) {
		// TODO Auto-generated method stub
		super.onCreate(aSavedInstanceStatea);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
	}

	// load control ...

	public void loadControl() {
		
		dataApplication = (DataApplication) getApplication();
		dataApplication.addActivity(this);
		layoutMenu = (LinearLayout) findViewById(R.id.layoutmenu);
		titleLayout = (LinearLayout) findViewById(R.id.title_layout);
		homeMenu = (Button) findViewById(R.id.homeMenu);
		homeMenu.setOnClickListener(this);
		profileMenu = (Button) findViewById(R.id.profileMenu);
		profileMenu.setOnClickListener(this);
		matchmakerMenu = (Button) findViewById(R.id.matchmakerMenu);
		matchmakerMenu.setOnClickListener(this);
		galleryMenu = (Button) findViewById(R.id.galleryMenu);
		galleryMenu.setOnClickListener(this);
		createMenu = (Button) findViewById(R.id.createMenu);
		createMenu.setOnClickListener(this);

	}

	@Override
	public void onClick(View aVa) {
		switch (aVa.getId()) {
		case R.id.homeMenu:
			Intent intent1 = new Intent(this, HomeActivity.class);
			startActivity(intent1);
			dataApplication.clearlistActivity();
			finish();
			break;
		case R.id.profileMenu:
			Intent intent2 = new Intent(this, ProfileActivity.class);
			startActivity(intent2);
			dataApplication.clearlistActivity();
			finish();
			break;
		case R.id.matchmakerMenu:
			Intent intent3 = new Intent(this, MatchmakerActivity.class);
			startActivity(intent3);
			dataApplication.clearlistActivity();
			finish();
			break;
		case R.id.galleryMenu:
			Intent intent4 = new Intent(this, GallerryActivity.class);
			startActivity(intent4);
			dataApplication.clearlistActivity();
			finish();
			break;
		case R.id.createMenu:
			Intent intent5 = new Intent(this, CreateActivity.class);
			startActivity(intent5);
			dataApplication.clearlistActivity();
			finish();
			break;
		default:
			break;
		}
	}
	
	@Override
	public void onBackPressed() {
		
		if(dataApplication.isHomeActivity()){
			dataApplication.clearlistActivity();
			finish();
		}else{
			finish();
		}		
		super.onBackPressed();
	}
}
